package gttp.nspa.client.adm.ui;

import com.sencha.gxt.widget.core.client.Dialog.PredefinedButton;
import com.sencha.gxt.widget.core.client.box.MessageBox;
import com.sencha.gxt.widget.core.client.info.Info;

final class ExceptionInfo {

    private static StringBuilder buildExInfo(Throwable t) {
        StringBuilder sb = new StringBuilder();
        StackTraceElement[] sts = t.getStackTrace();
        for (StackTraceElement st : sts) {
            sb.append(st.toString());
            sb.append('\n');
        }
        return sb;
    }

    public static void showInfo(Throwable t) {
        Info.display("Exception", buildExInfo(t).toString());
    }

    public static void showDialog(Throwable t, boolean modal) {
        MessageBox mb = new MessageBox("Exception", buildExInfo(t).toString());
        mb.setPredefinedButtons(PredefinedButton.OK);
        mb.setModal(modal);
        mb.show();
    }
}
